<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>

    <title>Title</title>

    <link rel="stylesheet" href="../../layui-v2.4.5/layui/css/layui.css" media="all">
    <script type="text/javascript" src="https://cdn.staticfile.org/jquery/2.2.1/jquery.min.js"></script>

    <script type="text/javascript" src="https://cdn.staticfile.org/plupload/2.1.9/moxie.js"></script>
    <script type="text/javascript" src="https://cdn.staticfile.org/plupload/2.1.9/plupload.dev.js"></script>
    <script type="text/javascript" src="https://cdn.staticfile.org/qiniu-js-sdk/1.0.14-beta/qiniu.min.js"></script>
    <script src="../../layui-v2.4.5/layui/layui.js" charset="utf-8"></script>


</head>
<body>
<form class="layui-form" action="">


    <div><h3 style="text-align: center;color: #00a2d4">图片管理</h3></div>
    <div style="margin-top: 125px;margin-left: 300px;">
        <div class="layui-upload" style="display: inline-block;vertical-align: top;margin-left: 10%">
            <button type="button" class="layui-btn" id="test1">上传海报</button>
            <div class="layui-upload-list">
                <input type="hidden" id="haibao" value="${record.poster}" name="haibao">
                <img class="layui-upload-img" id="demo1"  src="${record.poster}"  style="border:1px solid #009688;width: 150px;height: 150px;">
                <p id="frontViewText"></p>
            </div>
        </div>
        <div class="layui-upload" style="display: inline-block;vertical-align: top;">
            <button type="button" class="layui-btn" id="test2">上传打电话图标</button>
            <div class="layui-upload-list">
                <input type="hidden" id="callIcon" value="${record.callIcon}" name="callIcon">
                <img class="layui-upload-img" id="demo2" src="${record.callIcon}"  style="border:1px solid #009688;width: 150px;height: 150px;">
                <p id="reverseViewText"></p>
            </div>
        </div>
        <div class="layui-upload" style="display: inline-block;vertical-align: top;">
            <button type="button" class="layui-btn" id="test3">上传客服图标</button>
            <div class="layui-upload-list">
                <input type="hidden" id="serviceIcon" value="${record.serviceIcon}" name="serviceIcon">
                <img class="layui-upload-img" id="demo3"   src="${record.serviceIcon}" style="border:1px solid #009688;width: 150px;height: 150px;">
                <p id="profileViewText"></p>
            </div>
        </div>

        <div class="layui-upload" style="display: inline-block;vertical-align: top;">
            <button type="button" class="layui-btn" id="test4">上传二维码</button>
            <div class="layui-upload-list">
                <input type="hidden" id="qRcodeimg" value="${record.qRcodeimg}" name="qRcodeimg">
                <img class="layui-upload-img" id="demo4"   src="${record.qRcodeimg}" style="border:1px solid #009688;width: 150px;height: 150px;">

            </div>
        </div>


        <div class="layui-upload" style="display: inline-block;vertical-align: top;">
            <button type="button" class="layui-btn" id="test6">关于我们</button>
            <div class="layui-upload-list">
                <input type="hidden" id="aboutUs" value="${record.aboutUs}" name="aboutUs">
                <img class="layui-upload-img" id="demo6"   src="${record.aboutUs}" style="border:1px solid #009688;width: 150px;height: 150px;">

            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">客服电话</label>
            <div class="layui-input-block">
                <input type="text" name="serviceTel" lay-verify="required" value="${record.serviceTel}" autocomplete="off" placeholder="请输入客服电话" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <%--<button type="reset" class="layui-btn layui-btn-primary">重置</button>--%>
            </div>
        </div>

    </div>





</form>

<script>
    //Demo
    layui.use('form', function () {
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function (data) {
            //layer.msg(JSON.stringify(data.field));


            $.ajax({
                url: '/shop/uoloadShopIcon',
                type: 'POST', //GET
                async: true,    //或false,是否异步
                data: data.field,
                timeout: 5000,    //超时时间
                dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend: function (xhr) {
                    /*console.log(xhr)
                    console.log('发送前')*/
                },
                success: function (data) {
                    console.log(data);
                    if(data.result){
                        layer.msg("保存成功")
                        setTimeout(function () {
                            window.parent.location = window.parent.location.href

                        },1000)

                    }else {
                        layer.msg("发布失败")
                    }
                },
                error: function (xhr, textStatus) {
                    console.log('错误')
                    console.log(xhr)
                    console.log(textStatus)
                },
                complete: function () {
                    //console.log('结束')
                }
            })
            return false;
        });
    });


    layui.use('upload', function () {
        var $ = layui.jquery
            , upload = layui.upload;
        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            , url: '/shop/classTypeImgUpload?commodityId=${classRecord.id}'
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                    $.ajax({
                        url: '/qiniu/uploadImages',
                        type: 'POST', //GET
                        async: false,    //或false,是否异步
                        data: {
                            images: result.split(",")[1],
                            key:"/logo/"
                        },
                        timeout: 50000,    //超时时间
                        dataType: 'text',    //返回的数据格式：json/xml/html/script/jsonp/text
                        success: function (data) {
                            $("#haibao").val(data);
                        },
                    });
                });
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test2'
            , url: '/shop/classTypeImgUpload?commodityId=${classRecord.id}'
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo2').attr('src', result); //图片链接（base64）
                    $.ajax({
                        url: '/qiniu/uploadImages',
                        type: 'POST', //GET
                        async: false,    //或false,是否异步
                        data: {
                            images: result.split(",")[1],
                            key:"/logo/"
                        },
                        timeout: 50000,    //超时时间
                        dataType: 'text',    //返回的数据格式：json/xml/html/script/jsonp/text
                        success: function (data) {
                            $("#callIcon").val(data);
                        },
                    });
                });
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test3'
            , url: '/shop/classTypeImgUpload?commodityId=${classRecord.id}'
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo3').attr('src', result); //图片链接（base64）
                    $.ajax({
                        url: '/qiniu/uploadImages',
                        type: 'POST', //GET
                        async: false,    //或false,是否异步
                        data: {
                            images: result.split(",")[1],
                            key:"/logo/"
                        },
                        timeout: 50000,    //超时时间
                        dataType: 'text',    //返回的数据格式：json/xml/html/script/jsonp/text
                        success: function (data) {
                            $("#serviceIcon").val(data);
                        },
                    });
                });
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test4'
            , url: '/shop/classTypeImgUpload?commodityId=${classRecord.id}'
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo4').attr('src', result); //图片链接（base64）
                    $.ajax({
                        url: '/qiniu/uploadImages',
                        type: 'POST', //GET
                        async: false,    //或false,是否异步
                        data: {
                            images: result.split(",")[1],
                            key:"/logo/"
                        },
                        timeout: 50000,    //超时时间
                        dataType: 'text',    //返回的数据格式：json/xml/html/script/jsonp/text
                        success: function (data) {
                            $("#qRcodeimg").val(data);
                        },
                    });
                });
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });


        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test6'
            , url: '/shop/classTypeImgUpload?commodityId=${classRecord.id}'
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo6').attr('src', result); //图片链接（base64）
                    $.ajax({
                        url: '/qiniu/uploadImages',
                        type: 'POST', //GET
                        async: false,    //或false,是否异步
                        data: {
                            images: result.split(",")[1],
                            key:"/logo/"
                        },
                        timeout: 50000,    //超时时间
                        dataType: 'text',    //返回的数据格式：json/xml/html/script/jsonp/text
                        success: function (data) {
                            $("#aboutUs").val(data);
                        },
                    });
                });
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });

    });
</script>

</body>

<%--<script type="text/javascript" src="/admin/js/qiniu.js"></script>--%>

</html>
